package com.beagle.njddapp.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.owner.DIrverOrderBean;
import com.beagle.njddapp.core.UserService;
import com.beagle.njddapp.ui.adapter.inter.RecyclerViewItemClickLisenter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hxx
 * @date 2021-03-19 18:46
 * 农机主
 */
public class NjOrderDirverListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<DIrverOrderBean> dIrverOrderBeanList;
    private Context context;
    private RecyclerViewItemClickLisenter<DIrverOrderBean> onItemClickLisenter;
    private DirverOrderCzCallBack dirverOrderCzCallBack;

    public void setDirverOrderCzCallBack(DirverOrderCzCallBack dirverOrderCzCallBack) {
        this.dirverOrderCzCallBack = dirverOrderCzCallBack;
    }

    public void setOnItemClickLisenter(RecyclerViewItemClickLisenter<DIrverOrderBean> onItemClickLisenter) {
        this.onItemClickLisenter = onItemClickLisenter;
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DIrverOrderBean dIrverOrderBean = (DIrverOrderBean) view.getTag();
            if (view.getId() == R.id.tv_caozuo) {
                dirverOrderCzCallBack.caozuo(dIrverOrderBean);
            } else {
                onItemClickLisenter.onItemClickLisenter(dIrverOrderBean);
            }

        }
    };

    public NjOrderDirverListAdapter(List<DIrverOrderBean> dIrverOrderBeanList, Context context) {
        this.dIrverOrderBeanList = dIrverOrderBeanList;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_nj_dirver_order, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyHolder myHolder = (MyHolder) holder;
        DIrverOrderBean dIrverOrderBean = dIrverOrderBeanList.get(position);
        myHolder.tvNumber.setText(dIrverOrderBean.getMeshNum());
        myHolder.tvStart.setText(dIrverOrderBean.getBeginDate());
        myHolder.tvEnd.setText(dIrverOrderBean.getEndDate());
        myHolder.tvType.setText(dIrverOrderBean.getMeshTypeName());
        myHolder.tvAddress.setText(dIrverOrderBean.getWorkAddress());
        myHolder.tvPrice.setText(dIrverOrderBean.getWorkPrice());
        if (0 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("已取消");
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_cancle));
        } else if (1 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("待接单");
            myHolder.tvCz.setTextColor(Color.parseColor("#E56600"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (2 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("处理中");
            myHolder.tvCz.setTextColor(Color.parseColor("#E56600"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (3 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("待确认");
            myHolder.tvCz.setTextColor(Color.parseColor("#E15260"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_dirver_wait));
        } else if (4 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("使用中");
            myHolder.tvCz.setTextColor(Color.parseColor("#E56600"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_waitting));
        } else if (5 == dIrverOrderBean.getOrderStatus()) {
            myHolder.tvCz.setText("归还中");
            myHolder.tvCz.setTextColor(Color.parseColor("#E56600"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_waitting));
        }else if (6==dIrverOrderBean.getOrderStatus()){
            myHolder.tvCz.setText("已完成");
            myHolder.tvCz.setTextColor(Color.parseColor("#E56600"));
            myHolder.tvCz.setBackground(context.getResources().getDrawable(R.drawable.bg_oil_finish));
        }
        myHolder.tvCz.setTag(dIrverOrderBean);
        myHolder.tvCz.setOnClickListener(onClickListener);
        myHolder.itemView.setTag(dIrverOrderBean);
        myHolder.itemView.setOnClickListener(onClickListener);

    }

    @Override
    public int getItemCount() {
        return dIrverOrderBeanList.size();
    }

    public interface DirverOrderCzCallBack {
        void caozuo(DIrverOrderBean dIrverOrderBean);
    }

    public class MyHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_number_tv)
        TextView tvNumber;
        @BindView(R.id.item_type_tv)
        TextView tvType;
        @BindView(R.id.item_start_tv)
        TextView tvStart;
        @BindView(R.id.item_end_tv)
        TextView tvEnd;
        @BindView(R.id.item_address_tv)
        TextView tvAddress;
        @BindView(R.id.item_price_tv)
        TextView tvPrice;
        @BindView(R.id.item_status_tv)
        TextView tvCz;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
